package com.ruoyi.system.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.dto.DriverOrderDTO;
import com.ruoyi.system.domain.vo.DriverOrderVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DriverOrder;
import com.ruoyi.system.service.IDriverOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 货物运单Controller
 * 
 * @author ruoyi
 * @date 2024-06-16
 */
@RestController
@RequestMapping("/system/order")
public class DriverOrderController extends BaseController
{
    @Autowired
    private IDriverOrderService driverOrderService;

    /**
     * 查询货物运单列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(DriverOrderDTO driverOrder)
    {
        startPage();
        List<DriverOrderVO> list = driverOrderService.selectDriverOrderList(driverOrder);
        return getDataTable(list);
    }

    /**
     * 导出货物运单列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:export')")
    @Log(title = "货物运单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DriverOrderDTO driverOrder)
    {
        List<DriverOrderVO> list = driverOrderService.selectDriverOrderList(driverOrder);
        ExcelUtil<DriverOrderVO> util = new ExcelUtil<DriverOrderVO>(DriverOrderVO.class);
        util.exportExcel(response, list, "货物运单数据");
    }

    /**
     * 获取货物运单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:order:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(driverOrderService.selectDriverOrderById(id));
    }

    /**
     * 新增货物运单
     */
    @PreAuthorize("@ss.hasPermi('system:order:add')")
    @Log(title = "货物运单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DriverOrder driverOrder)
    {
        driverOrder.setCreatime(new Date());
        return toAjax(driverOrderService.insertDriverOrder(driverOrder));
    }

    /**
     * 修改货物运单
     */
    @PreAuthorize("@ss.hasPermi('system:order:edit')")
    @Log(title = "货物运单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DriverOrder driverOrder)
    {
        driverOrder.setUpdatetime(new Date());
        return toAjax(driverOrderService.updateDriverOrder(driverOrder));
    }

    /**
     * 删除货物运单
     */
    @PreAuthorize("@ss.hasPermi('system:order:remove')")
    @Log(title = "货物运单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(driverOrderService.deleteDriverOrderByIds(ids));
    }

    /**
     * 运单价格计算
     * @param driverOrder
     * @return
     */
    @GetMapping("/driverOrderPrice")
    public AjaxResult driverOrderPrice(DriverOrderDTO driverOrder)
    {
        return success(driverOrderService.getDriverOrderPrice(driverOrder));
    }
}
